﻿using HybridLab.Virtual;
using HybridLab.Virtual.Interfaces;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace HybridLab.Workflow.Activities.UI
{
	public partial class ConnectToVirtualHostForm : Form
	{
		public IVirtualHost Host { get; private set; }

		public ConnectToVirtualHostForm(string hostType, string hostName, string domain, string username, string password)
		{
			InitializeComponent();
			GetHostTypes();
			cmbHostType.SelectedItem = hostType;
			txtHostName.Text = hostName;
			txtDomain.Text = domain;
			txtPassword.Text = password;
			txtUsername.Text = username;
		}

		private void GetHostTypes()
		{
			cmbHostType.DataSource = VirtualHostCatalog.GetHostTypes();
		}

		private void btnOK_Click(object sender, EventArgs e)
		{
			Host = null;
			try
			{
				Cursor = Cursors.WaitCursor;
				Host = VirtualHostCatalog.GetHost(cmbHostType.SelectedItem.ToString(), txtHostName.Text, txtDomain.Text, txtUsername.Text, txtPassword.Text);

				DialogResult = DialogResult.OK;
				Close();
			}
			catch (Exception ex)
			{
				MessageBox.Show(ex.Message);
			}
			finally
			{
				Cursor = Cursors.Arrow;
			}
		}

		private void btnCancel_Click(object sender, EventArgs e)
		{
			DialogResult = DialogResult.Cancel;
			Close();
		}
	}
}
